package org.myorg.v4;

import java.util.Arrays;
import java.util.Random;



public class PassWord {
	static int p[] = {0,1,2,3,4,0,1,2,3,4};
	//static int p[] = {0,1,2,3};
	static int pn = 1;
	static int pl = 10;
	static int nl = 8;
	//static int pl = 4;
	//static int nl = 5;
	static int id[][] = new int[pn][pl];
	
	static void init(){
		for (int i = 0; i < pn; i++) {
			for (int j = 0; j < pl; j++) {
				Random r =new Random();
				id[i][j] = r.nextInt(nl);
			}
		}
//		for (int i = 0; i < pl; i++) {
//			Random r =new Random();
//			p[i] = r.nextInt(pl);
//		}
//		System.out.print("new password " );
//		for (int x: p ){
//			System.out.print(x);	
//		}
//		System.out.print("\n");	
	}
	
	public static double passWord(){
		double it=0;
		
		init();
		while (!Arrays.equals(id[0], p)) {
			int pos = new Random().nextInt(pl);
//			while(true){
//				int t = new Random().nextInt(pl+1);
//				if (id[0][pos] != t) {
//					id[0][pos] = t;
//					break;
//				}
//			}
			id[0][pos] = new Random().nextInt(nl);
			
//			System.out.print("password " );
//			for (int x: id[0] ){
//				System.out.print(x);	
//			}
//			System.out.print("\n");	
			it++;
//			if(it > 1000) {
//				break;
//			}
		}
		System.out.println("iteration number is: " + it);
		System.out.print("password is: ");
		for (int x: id[0] ){
			System.out.print(x);	
		}
		System.out.print("\n");	
		return it;
	}
	
	public static void main(String args[]) {
		
		double mit = 0;
		double mrt = 0;
		
		
		String recordtime = "";
		
		String recordit = "";
		for (int i = 0; i < 100; i++) {
			long st = System.currentTimeMillis();
			
			double it = passWord();
			
			long rt = System.currentTimeMillis() - st;
			mit = mit + it;
			mrt = mrt + rt;
			recordit = recordit + "\t" + it;
			recordtime = recordtime + "\t" + rt;
		}
		
		
		System.out.println("iteration number is: " + mit);
		
		String res = "iterator: " + recordit + "\n" + "time: " + recordtime + 
		"\n" + "sum iterator: " + mit + "\n" +"sum time: " + mrt;
		
		
		RWF4.wlf(res.getBytes(), "res/pw");
		
		System.out.println("leave main");
	}
	
}
